package com.mnb.beidou.model;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

/**
 * 水位及气象数据实体类
 */
@Data
public class DataEntity {
    // 雷达水位（地址35001）
    private double radarWaterLevel;
    // 雷达空高（地址35003）
    private double radarEmptyHeight;
    // 压力水位（地址35005）
    private double pressureWaterLevel;
    // 当前雨量（地址35007）
    private double currentRainfall;
    // 累计雨量（地址35008）
    private double totalRainfall;
    // 温度（地址35010）
    private double temperature;
    // 湿度（地址35012）
    private double humidity;
    // 大气压（地址35014）
    private double atmosphericPressure;
    // 多普勒水位（地址35016）
    private double dopplerWaterLevel;
    // 瞬时流量（地址35018）
    private double instantaneousFlow;
    // 累计流量（地址35020）
    private double totalFlow;
    // 电源电压（地址35022）
    private double powerVoltage;
    // 信号质量（地址35023）
    private double signalQuality;
    // 多普勒温度（35028）
    private double dopplerTemperature;
    // 流速（35030）
    private double flowVelocity;

    private String msgJson;

    @Override
    public String toString() {
        return "数据实体{" +
                "雷达水位=" + radarWaterLevel + "m, " +
                "雷达空高=" + radarEmptyHeight + "m, " +
                "压力水位=" + pressureWaterLevel + "m, " +
                "当前雨量=" + currentRainfall + "mm, " +
                "累计雨量=" + totalRainfall + "mm, " +
                "温度=" + temperature + "℃, " +
                "湿度=" + humidity + "%RH, " +
                "大气压=" + atmosphericPressure + "Kpa, " +
                "多普勒水位=" + dopplerWaterLevel + "m, " +
                "瞬时流量=" + instantaneousFlow + "m³/s, " +
                "累计流量=" + totalFlow + "m³, " +
                "电源电压=" + powerVoltage + "V, " +
                "信号质量=" + signalQuality + "dB, " +
                "多普勒温度=" + dopplerTemperature + "℃, " +
                "流速=" + flowVelocity + "m/s" +
                '}';
    }

    public String toJsonString() {
        ObjectMapper objectMapper = new ObjectMapper();

        try {
            return objectMapper.writeValueAsString(new Object() {
                public final String 雷达水位 = radarWaterLevel + "m";
                public final String 雷达空高 = radarEmptyHeight + "m";
                public final String 压力水位 = pressureWaterLevel + "m";
                public final String 当前雨量 = currentRainfall + "mm";
                public final String 累计雨量 = totalRainfall + "mm";
                public final String 温度 = temperature + "℃";
                public final String 湿度 = humidity + "%RH";
                public final String 大气压 = atmosphericPressure + "Kpa";
                public final String 多普勒水位 = dopplerWaterLevel + "m";
                public final String 瞬时流量 = instantaneousFlow + "m³/s";
                public final String 累计流量 = totalFlow + "m³";
                public final String 电源电压 = powerVoltage + "V";
                public final String 信号质量 = signalQuality + "dB";
                public final String 多普勒温度 = dopplerTemperature + "℃";
                public final String 流速 = flowVelocity + "m/s";
            });
        } catch (JsonProcessingException e) {
            // 转换失败时返回默认字符串
            return "数据实体转换JSON失败: " + e.getMessage();
        }
    }

}
